package kov.core
{
	import com.riaoo.display.Animation;
	import com.riaoo.display.FrameSequence;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.geom.Rectangle;
	
	import kov.core.body.zy.ZhaoYun;
	import kov.core.global.Global;
	import kov.display.AdvancedAnimation;
	import kov.geom.Cube;

	/**
	 * 地图数据。描述了地图背景、前景，长宽等数据。
	 * @author jiangxuejian
	 */	
	public class MapData
	{
		[Embed("../../../assets/static/map/map.png")]
		private var Map:Class;
		[Embed("../../../assets/static/map/side.png")]
		private var Side:Class;
		
		[Embed("../../../assets/static/qi/0.gif")]
		private var Qi0:Class;
		[Embed("../../../assets/static/qi/1.gif")]
		private var Qi1:Class;
		[Embed("../../../assets/static/qi/2.gif")]
		private var Qi2:Class;
		[Embed("../../../assets/static/qi/3.gif")]
		private var Qi3:Class;
		[Embed("../../../assets/static/qi/4.gif")]
		private var Qi4:Class;
		[Embed("../../../assets/static/qi/5.gif")]
		private var Qi5:Class;
		[Embed("../../../assets/static/qi/6.gif")]
		private var Qi6:Class;
		
		[Embed("../../../assets/static/shadai/0.gif")]
		private var Shadai:Class;
		
		
		private var _width:Number;
		private var _height:Number;
		private var _blockData:BlockData;
		
		/**
		 * 地图宽度。单位：像素。
		 */		
		public function get width():Number
		{
			return _width;
		}
		
		/**
		 * 地图高度。单位：像素。
		 */		
		public function get height():Number
		{
			return _height;
		}
		
		/**
		 * 不可走数据。
		 */		
		public function get blockData():BlockData
		{
			return _blockData;
		}
		
		/**
		 * 构造函数。
		 * @param width
		 * @param height
		 * @param blockData
		 */		
		public function MapData(blockData:BlockData)
		{
			_blockData = blockData;
		}
		
		/**
		 * Body 层的物品。
		 */		
		public function getBodyground():Vector.<IBody>
		{
			var result:Vector.<IBody> = new Vector.<IBody>();
			
			var dai:Body = new Body(new Cube(0, 0, 0, 84, 47));
			var fs:FrameSequence = new FrameSequence();
			fs.push((new Shadai() as Bitmap).bitmapData);
			dai.renderer.frameSequence = fs;
			dai.renderer.offsetX = 47;
			dai.renderer.offsetY = 31;
			dai.renderer.play();
			dai.locateAt(270, 170, 0);
			
			result.push(dai);
			return result;
		}
		
		/**
		 * 地图背景。
		 */		
		public function getBackground():Bitmap
		{
			var bmp:Bitmap = new Map() as Bitmap;
			_width = bmp.width;
			_height = bmp.height;
			
			// 设置边界不可走
			_blockData.addBlock(new Rectangle(-100, -100, 100, _height + 200)); // 左
			_blockData.addBlock(new Rectangle(0, -100, _width, 100)); // 上
			_blockData.addBlock(new Rectangle(_width, -100, 100, _height + 200)); // 右
			_blockData.addBlock(new Rectangle(0, _height, _width, 100)); // 下
			
			return bmp;
		}
		
		/**
		 * 地图前景。
		 */		
		public function getFrontground():Vector.<Bitmap>
		{
			var result:Vector.<Bitmap> = new Vector.<Bitmap>();
			
			var side:Bitmap = new Side() as Bitmap;
			side.y = 195;
			result.push(side);
			
			var qi:Animation = getQi();
			qi.x = 275;
			qi.y = 118;
			qi.play();
			result.push(qi);
			
			return result;
		}
		
		private function getQi():Animation
		{
			var qi0:BitmapData = (new Qi0() as Bitmap).bitmapData;
			var qi1:BitmapData = (new Qi1() as Bitmap).bitmapData;
			var qi2:BitmapData = (new Qi2() as Bitmap).bitmapData;
			var qi3:BitmapData = (new Qi3() as Bitmap).bitmapData;
			var qi4:BitmapData = (new Qi4() as Bitmap).bitmapData;
			var qi5:BitmapData = (new Qi5() as Bitmap).bitmapData;
			var qi6:BitmapData = (new Qi6() as Bitmap).bitmapData;
			
			var fs:FrameSequence = new FrameSequence();
			fs.push(qi0);
			fs.push(qi1);
			fs.push(qi2);
			fs.push(qi3);
			fs.push(qi4);
			fs.push(qi5);
			fs.push(qi6);
			
			return new Animation(Global.timer, fs);
		}
		
	}
}